import time

# 导入库
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support.select import Select
# 创建浏览器驱动对象
driver=webdriver.Edge()
driver.maximize_window()
# 打开测试页面
driver.get("https://shop.aircheng.com/simple/login")
# 对页面中的元素进行操作
# driver.find_element:返回是一个页面的元素
# send_keys("admin")  对页面元素进行传入值
driver.find_element(By.XPATH,"//input[@name='login_info']").send_keys("renpan")
driver.find_element(By.XPATH,"//input[@name='password']").send_keys("12345678")
driver.find_element(By.XPATH,"//input[@value='登录']").click()

time.sleep(3)

ele=(WebDriverWait(driver, 8,0.5).
 until(lambda x: x.find_element(By.XPATH,"//input[@name='word']")))
ele.send_keys("手机")

driver.find_element(By.XPATH,"//i[@class='fa fa-search']").click()
time.sleep(2)
# js="window.scrollTo(0,600)"
# driver.execute_script(js)

ele1=(WebDriverWait(driver, 10,0.5).
 until(lambda x: x.find_element(By.XPATH,"//img[@alt='毕亚兹 车载手机支架 C21 空调出风口磁吸式支架 炫酷黑手机平板']")))
ele1.click()

#
time.sleep(2)
handles = driver.window_handles
driver.switch_to.window(handles[1])

ele3=(WebDriverWait(driver, 30,0.5).
 until(lambda x: x.find_element(By.XPATH,"//span[@id='16272070']//img")))
ele3.click()

driver.find_element(By.CSS_SELECTOR,"div[id='buyNowButton']").click()


ele5=(WebDriverWait(driver, 10,0.5).
 until(lambda x: x.find_element(By.XPATH,"//a[contains(text(),'添加新地址')]")))
ele5.click()

time.sleep(3)

time.sleep(5)
ele6=driver.find_element(By.XPATH, "//iframe[@name='OpenaddressWindow']")
driver.switch_to.frame(ele6)

driver.find_element(By.CSS_SELECTOR,"input[name='accept_name']").send_keys("admin")

driver.find_element(By.CSS_SELECTOR, "input[name='accept_name']").send_keys("张三")
Select(driver.find_element(By.CSS_SELECTOR, "select[name='province']")).select_by_visible_text("河北省")
time.sleep(1)

Select(driver.find_element(By.CSS_SELECTOR, "select[name='city']")).select_by_visible_text("唐山市")
time.sleep(1)
Select(driver.find_element(By.CSS_SELECTOR, "select[name='area']")).select_by_visible_text("路北区")
driver.find_element(By.XPATH, "//input[@name='address']").send_keys("某某小区")
driver.find_element(By.XPATH, "//input[@name='mobile']").send_keys("13800138006")
driver.find_element(By.XPATH, "//input[@name='telphone']").send_keys("13800138007")
driver.find_element(By.XPATH, "//input[@name='zip']").send_keys("123456")

driver.switch_to.default_content()
driver.find_element(By.CSS_SELECTOR,"button[class=' aui_state_highlight']").click()




# ele2 = driver.find_element(By.XPATH, "//input[@id='buyNums']")
# ele2.click()
# driver.implicitly_wait(1)
# ele2.click()
# ele2.send_keys("5")

# ele4=(WebDriverWait(driver, 5,0.5).
#  until(lambda x: x.find_element(By.XPATH,"//span[contains(text(),'立即购买')]")))
# ele4.click()
#
# ele5=(WebDriverWait(driver, 10,0.5).
#  until(lambda x: x.find_element(By.XPATH,"//a[contains(text(),'添加新地址')]")))
# ele5.click()
#
# time.sleep(5)
# ele6=driver.find_element(By.XPATH, "//iframe[@name='OpenaddressWindow']")
# driver.switch_to.frame(ele6)
#
# driver.find_element(By.CSS_SELECTOR, "input[name='accept_name']").send_keys("张三")
# Select(driver.find_element(By.CSS_SELECTOR, "select[name='province']")).select_by_visible_text("河北省")
# time.sleep(1)
#
# Select(driver.find_element(By.CSS_SELECTOR, "select[name='city']")).select_by_visible_text("唐山市")
# time.sleep(1)
# Select(driver.find_element(By.CSS_SELECTOR, "select[name='area']")).select_by_visible_text("路北区")
# driver.find_element(By.XPATH, "//input[@name='address']").send_keys("某某小区")
# driver.find_element(By.XPATH, "//input[@name='mobile']").send_keys("13800138006")
# driver.find_element(By.XPATH, "//input[@name='telphone']").send_keys("13800138007")
# driver.find_element(By.XPATH, "//input[@name='zip']").send_keys("123456")
# driver.switch_to.default_content()
# driver.find_element(By.CSS_SELECTOR,"body > div.aui_state_focus > div > table > tbody > tr:nth-child(2) > td.aui_c > div > table > tbody > tr:nth-child(3) > td > div > button.aui_state_highlight").click()
# driver.find_element(By.CSS_SELECTOR,"input[value='1'][name='delivery_id']").click()
# driver.find_element(By.CSS_SELECTOR,"input[title='预存款']").click()
# js="window.scrollTo(200,1000)"
# driver.execute_script(js)
# driver.find_element(By.CSS_SELECTOR,"label[class='cart_topay_btn'] span").click()
# time.sleep(1)
# table = driver.find_element(By.CSS_SELECTOR, "body > div.home_content > section.cart_3 > div > table:nth-child(3) > tbody")
# print(table.text)

time.sleep(30)
driver.quit()